﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;


namespace PressMenu2
{
    class MyMouse
    {
        private  MouseState oldMouseState;
        private  MouseState newMouseState;
        private long lastTimeEvent=0;
        private bool bLeftButtonJustPress = false;

       

        public void Update()
        {
            lastTimeEvent++;
            oldMouseState = newMouseState;
            newMouseState = Mouse.GetState();

            // fault --------------------------------------------------
            if (oldMouseState != newMouseState) 
            {
                lastTimeEvent++;
                if (oldMouseState.LeftButton == newMouseState.LeftButton)
                    bLeftButtonJustPress = false;
                else 
                    bLeftButtonJustPress = true; // Up != Down :((
            }
            //----------------------------------------------------------
            
        }

        public  int X
        {
            get {return newMouseState.X;}
        }

        public  int Y
        {
            get { return newMouseState.Y; }
        }

        public  bool isOver(Rectangle rectangle)
        {
            if (rectangle.Left < newMouseState.X && newMouseState.X < rectangle.Right)
                if (rectangle.Top < newMouseState.Y && newMouseState.Y < rectangle.Bottom)
                    return true;
            return false;
        }
        
        public bool IsLeftClick()
        {
            if (oldMouseState.LeftButton == ButtonState.Released)
                if (newMouseState.LeftButton == ButtonState.Pressed)
                    return true;
            return false;
        }
        public bool IsRightClick()
        {
            if (oldMouseState.RightButton == ButtonState.Released)
                if (newMouseState.RightButton == ButtonState.Pressed)
                    return true;
            return false;
        }
      
        public MyMouse()
        {
            oldMouseState = new MouseState();
            newMouseState = new MouseState();
            oldMouseState = Mouse.GetState();
        }
    }
}
